import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner scan=new Scanner(System.in);
        int m=scan.nextInt();
        int n=scan.nextInt();
        StringBuilder s=new StringBuilder();
        String table="0123456789ABCDEF";
        if(m==0){
            System.out.println(0);
        }
        boolean flg=false;
        if(m<0){
            m=-m;
            flg=true;
        }
        while(m>0){
            s.append(table.charAt(m%n));
            m/=n;
        }
        if(flg){
            s.append("-");
        }
        s.reverse();
        System.out.println(s);
    }
}
